﻿using System;
using System.Collections;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using BCDataCenter;
using BCDataCenter.BOL;

using System.ComponentModel;
using System.Drawing;
using System.Web.SessionState;
using System.Web.UI.HtmlControls;


public partial class WebUserControl_InBaoCao : System.Web.UI.UserControl
{
    string error = "";
    protected static Hashtable handlerPages = new Hashtable();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadListNghiepVu();
            try
            {
                if (DropListNghiepVu.SelectedIndex != -1)
                {
                    LoadListNghiepVuCanIn(DropListNghiepVu.SelectedItem.Value);
                }
            }
            catch
            {
                return;
            }
        }
        
    }

    private void LoadListNghiepVu()
    {
        BWInCacNghiepVuKho obj = new BWInCacNghiepVuKho();
        DropListNghiepVu.DataSource = obj.GetListLoaiNghiepVu(ref error);
        DropListNghiepVu.DataTextField = "trndesc";
        DropListNghiepVu.DataValueField = "trntyp";
        DropListNghiepVu.DataBind();
    }
   
    private void LoadListNghiepVuCanIn(string trntyp)
    {
        try
        {
            BWInCacNghiepVuKho obj = new BWInCacNghiepVuKho();
            gvListNghiepVuCanIn.DataSource = obj.GetListNghiepVuCanIn(ref error, trntyp, Session["Sitecode"].ToString());
            gvListNghiepVuCanIn.DataBind();
        }
        catch (Exception ex)
        {
            return;
            
        }
    }
    protected void DropListNghiepVu_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (DropListNghiepVu.SelectedIndex != -1)
        {
            LoadListNghiepVuCanIn(DropListNghiepVu.SelectedItem.Value);
        } 

    }
    protected void gvListNghiepVuCanIn_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.Equals("Printed"))
        {
            string selectedValue = "";
            GridViewRow gvr = ((Control)e.CommandSource).NamingContainer as GridViewRow;
            selectedValue = gvr.Cells[1].Text;
            if (selectedValue != null)
            {

                Session["SoChungTu"] = selectedValue;
                Session["LoaiNghiepVu"] = DropListNghiepVu.SelectedItem.Value;
               
                Session["TenLoaiNghiepVu"] = DropListNghiepVu.SelectedItem.Text;
                BWInCacNghiepVuKho obj = new BWInCacNghiepVuKho();
                try
                {
                    obj.UpdatePrinted(ref error, selectedValue);
                    if (DropListNghiepVu.SelectedIndex != -1)
                    {
                        LoadListNghiepVuCanIn(DropListNghiepVu.SelectedItem.Value);
                    }
                    System.Text.StringBuilder sb = new System.Text.StringBuilder();
                    sb.Append("window.open('" + Globals.ApplicationPath + "WebMaster/Administrator/InNghiepVuKho/Print.aspx','PrintMe', 'height=900px,width=900px,scrollbars=1');");
                    ScriptManager.RegisterClientScriptBlock(this.UpdatePanel1, this.UpdatePanel1.GetType(), "NewClientScript", sb.ToString(), true);
                }
                catch
                {
                    return;
                }
            }
            else
            {
                Session["SoChungTu"] = null;
                Session["LoaiNghiepVu"] = null;
               
                Session["TenLoaiNghiepVu"] = null;
                return;

            }
        }
    }
    protected void gvListNghiepVuCanIn_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        gvListNghiepVuCanIn.PageIndex = e.NewPageIndex;
        if (DropListNghiepVu.SelectedIndex != -1)
        {
            LoadListNghiepVuCanIn(DropListNghiepVu.SelectedItem.Value);
        } 
    }

   
}
